package com.heima.controller;

import com.heima.pojo.Cooperative;
import com.heima.pojo.dto.ReceiveDto;
import com.heima.pojo.vo.PagingVO;
import com.heima.pojo.vo.PolicyVO;
import com.heima.service.CooperativeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
@Slf4j
public class CooperativeController {
    @Autowired
    private CooperativeService cooperativeService;

    //查询合作商
    @GetMapping("/search")
    private PagingVO SelectCooperative(ReceiveDto dto){
        log.info("查询合作商{}",dto);
        PagingVO pvo = cooperativeService.SelectCooperative(dto);
        return pvo;
    }
    //新增合作商
    @PostMapping
    private Boolean addCooperative(@RequestBody Cooperative cooperative){
        log.info("新增合作商{}",cooperative);
        return cooperativeService.addCooperative(cooperative);
    }
    //获取合作商详情
    @GetMapping("/{id}")
    private PolicyVO getCooperative(@PathVariable Long id){
        log.info("获取合作商详情{}",id);
        return cooperativeService.getCooperative(id);
    }
    //修改合作商
    @PutMapping("{id}")
    private Boolean UpdateCooperative(@RequestBody PolicyVO policyVo , @PathVariable Long id){
        log.info("修改合作商参数为：{}----{}",id,policyVo);
        return cooperativeService.UpdateCooperative(policyVo,id);

    }
    //删除合作商
    @DeleteMapping("/{id}")
    private Boolean deleteCooperative(@PathVariable Long id){
        log.info("删除合作商{}",id);
        return cooperativeService.deleteCooperative(id);
    }

}
